package com.woniuxy.servcie.impl;

import com.woniuxy.dao.RbacManagerDao;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.pageDto;
import com.woniuxy.servcie.RbacManagerservice;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 佘赛飞
 * @create 2021-11-25 8:20 下午
 */
@Service
public class RbacManagerserviceImpl implements RbacManagerservice {
    @Autowired
    RbacManagerDao rbacManagerDao;
    @Override
    public RbacManager findOne(int id) {
        return rbacManagerDao.findOne(id);
    }

    @Override
    public List <RbacManager> findAll() {
        return rbacManagerDao.findAll();
    }

    @Override
    public Integer addManager(RbacManager manager) {
        //提供，新增用户时候，密码加密功能
        String password = manager.getPassword();
        //就是一个加密算法，别人写好的，中间的password，是目标被加密的对象，最后的一个参数是salt盐（加密结果受到盐的影响）
        SimpleHash simpleHash = new SimpleHash("MD5",password,manager.getAccount()+"woniuxy");
        String nwePassword = simpleHash.toHex();
        manager.setPassword(nwePassword);
        return rbacManagerDao.addManager(manager);
    }

    @Override
    public Integer Update(RbacManager manager) {
         return rbacManagerDao.Update(manager);
    }

    @Override
    public Integer deleteManager(int id) {
        Integer integer = rbacManagerDao.deleteManager(id);
        return integer;
    }

    @Override
    public Integer deleteOne(RbacManager manager) {
        return rbacManagerDao.deleteOne(manager);
    }

    @Override
    public List <RbacManager> FindAllAndPagination(pageDto pageDtos) {
        return rbacManagerDao.FindAllAndPagination(pageDtos);
    }
}
